package com.chen.librarysystem.config;

import java.sql.Connection;
import java.sql.SQLException;

public class MysqlManager {
    private static final String JDBC_URL = "jdbc:mysql://localhost:3306/spring_db";
    private static final String JDBC_USER = "root";
    private static final String JDBC_PASSWORD = "123456";
    private static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";

    public static void connect() throws SQLException, ClassNotFoundException {
        Class.forName(JDBC_DRIVER); // 加载驱动
        try (Connection conn = java.sql.DriverManager.getConnection(JDBC_URL, JDBC_USER, JDBC_PASSWORD)) {
            System.out.println("数据库连接成功！");
            System.out.println("数据库版本：" + conn.getMetaData().getDatabaseProductVersion());
            System.out.println("数据库用户名：" + conn.getMetaData().getUserName());
            System.out.println("数据库URL：" + conn.getMetaData().getURL());
            System.out.println("数据库驱动：" + conn.getMetaData().getDriverName());
            System.out.println("数据库驱动版本：" + conn.getMetaData().getDriverVersion());
        }
    }

    public static void main(String[] args) {
        try {
            connect();
        } catch (SQLException | ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
}

